package com.yuzhi.master.drainSms.controller;

import java.util.List;
import java.util.Arrays;

import com.yuzhi.common.core.controller.BaseController;
import com.yuzhi.common.core.domain.ApiResult;
import com.yuzhi.common.core.page.PageDataInfo;
import com.yuzhi.common.core.validate.AddGroup;
import com.yuzhi.common.util.poi.ExcelUtil;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.yuzhi.master.drainSms.domain.vo.DrainSmsInfoVo;
import com.yuzhi.master.drainSms.domain.bo.DrainSmsInfoBo;
import com.yuzhi.master.drainSms.domain.request.DrainSmsInfoReq;
import com.yuzhi.master.drainSms.service.IDrainSmsInfoService;


/**
 * 短信消息明细
 *
 * @author coding123
 * @date 2025-08-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/drainSmsInfo")
public class DrainSmsInfoController extends BaseController {

    private final IDrainSmsInfoService idrainSmsInfoService;

    /**
     * 查询短信消息明细列表
     */
    @SaCheckPermission("system:drainSmsInfo:list")
    @PostMapping("/list")
    public ApiResult<PageDataInfo> list(@RequestBody DrainSmsInfoReq request) {
        return ApiResult.ok(idrainSmsInfoService.queryPageList(request));
    }

    /**
     * 导出短信消息明细列表
     */
    @SaCheckPermission("system:drainSmsInfo:export")
    @PostMapping("/export")
    public void export(DrainSmsInfoReq request, HttpServletResponse response) {
        List<DrainSmsInfoVo> list = idrainSmsInfoService.queryList(request);
        ExcelUtil.exportExcel(list, "短信消息明细", DrainSmsInfoVo.class, response);
    }

    /**
     * 获取短信消息明细详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:drainSmsInfo:query")
    @GetMapping("/getInfoById/{id}")
    public ApiResult<DrainSmsInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return ApiResult.ok(idrainSmsInfoService.queryById(id));
    }

    /**
     * 新增短信消息明细
     */
    @SaCheckPermission("system:drainSmsInfo:add")
    @PostMapping("/add")
    public ApiResult<Void> add(@Validated(AddGroup.class) @RequestBody DrainSmsInfoBo bo) {
        return toAjax(idrainSmsInfoService.insertByBo(bo));
    }

    /**
     * 修改短信消息明细
     */
    @SaCheckPermission("system:drainSmsInfo:edit")
    @PostMapping("/edit")
    public ApiResult<Void> edit(@Validated(AddGroup.class) @RequestBody DrainSmsInfoBo bo) {
        return toAjax(idrainSmsInfoService.updateByBo(bo));
    }

    /**
     * 删除短信消息明细
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:drainSmsInfo:remove")
    @DeleteMapping("/removeBatchById/{ids}")
    public ApiResult<Void> removeBatchById(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(idrainSmsInfoService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 删除短信消息明细
     *
     * @param id 主键
     */
    @SaCheckPermission("system:drainSmsInfo:remove")
    @DeleteMapping("/removeById/{id}")
    public ApiResult<Void> removeById(@NotEmpty(message = "主键不能为空")
                                  @PathVariable String id) {
        return toAjax(idrainSmsInfoService.deleteById(id, true));
    }
}
